package cn.doitedu.hbase.phoenix;

import java.sql.*;

public class PhoenixJDBC {

    public static void main(String[] args) throws SQLException {
        Statement stmt = null;
        ResultSet rset = null;

        // URI :    schema + authority + host + port
        Connection con = DriverManager.getConnection("jdbc:phoenix:spark01,spark02,spark03:2181");
        stmt = con.createStatement();

        /*// 建表
        stmt.executeUpdate("create table test (a integer not null primary key, b varchar)");

        // 插入或更新数据
        stmt.executeUpdate("upsert into test values (1,'Hello')");
        stmt.executeUpdate("upsert into test values (2,'World!')");
        con.commit();*/

        // 查询数据
        PreparedStatement statement = con.prepareStatement("select * from ILOVEYOU");
        rset = statement.executeQuery();
        while (rset.next()) {
            System.out.println(rset.getString("id") + "\t" +   rset.getString("name") +   rset.getString("addr"));
        }
        statement.close();
        con.close();
    }

}
